package cn.doctorpda.conference.presenter;

import org.json.JSONException;
import org.json.JSONObject;

import cn.doctorpda.conference.bean.Msg;
import cn.doctorpda.conference.config.NetConfig;
import cn.doctorpda.conference.model.GetChangePasswordModel;
import cn.doctorpda.conference.model.IPostModel;
import cn.doctorpda.conference.okhttp.callback.StringCallback;
import cn.doctorpda.conference.utils.GsonUtil;
import cn.doctorpda.conference.view.callbackview.IChangePersonalBaseView;
import okhttp3.Call;

/**
 * Created by huangjinlong on 2016/5/19.
 */
public class ChangePasswordPresenter {
    private IPostModel model;
    private IChangePersonalBaseView changePSWView;

    public ChangePasswordPresenter(IChangePersonalBaseView baseView) {
        model = new GetChangePasswordModel();
        changePSWView = (IChangePersonalBaseView)baseView;
    }

    public void getNewPSWData(String mobile,String old_password,String new_password ) {
        model.postNetWorkStringData(NetConfig.GET_CHANGE_PSW, new StringCallback() {
            @Override
            public void onError(Call call, Exception e) {
                changePSWView.setNewError(call, e);
            }

            @Override
            public void onResponse(String response) {
                try {
                    Msg msg = GsonUtil.fromJson(response, Msg.class);
                    JSONObject jsonObject = new JSONObject(response);
                    changePSWView.setNewView(msg);

                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }, mobile,old_password,new_password);
    }
}
